require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#chatSettings",
    data:{
        id:"",
        userInfo:{},
        isShare:false
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.id=this.searchObject&&this.searchObject.id;
        // this.isMain=this.searchObject&&this.searchObject.isMain;
        //this.getGroupMemberInfo();
        this.getUserInfo();
        // this.myRepliesPosts();
    },
    methods:{
        //后退
        getBack: function () {
            history.go(-1);
            // if(this.square==1){
            //     location.href="/friend/circleSquare";
            // }else{
            //     location.href="/friend?indexs=3";
            // }
            //location.href="/friend?indexs=3";
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //tab切换
        getTab:function(num){
            this.value=num;
            this.pageNumber=1;
        },
        //用户信息
        getUserInfo:function() {
            var that = this;
            var data = {
                loginUid:userInfo.loginUid,
                id:that.id
            };
            this.ajax({url:"/user/getUserInfo", data: data, dataType: "json", method: "post"}, function (b) {
                if (b.json.code == 0 && b.json.data) {
                    that.userInfo= b.json.data;
                    //console.log(that.categoryList)
                } else {
                    vm.$refs.prompt.toast("获取信息失败！")
                }
            });
        },
        //加入黑名单
        addBlack:function() {
            var that = this;
            var data = {
                loginUid:userInfo.loginUid,
                friendId:that.id
            };
            this.ajax({url:"/happyi/addBlack", data: data, dataType: "json", method: "post"}, function (b) {
                if (b.json.code == 0) {
                    //console.log(that.categoryList)
                    vm.$refs.prompt.toast("拉黑成功！")
                } else {
                    vm.$refs.prompt.toast("拉黑失败！")
                }
            });
        },
        getShare:function(){
            this.isShare=!this.isShare;
        },
        getChoice:function(num){
            if(num==1){
                location.href="/friend/choiceList?number=9&postId="+this.id;
            }else{
                location.href="/friend/forward?number=9&postId="+this.id;
            }

        },
        getNext:function(){
            location.href="/friend/postRecycling"
        }
    }
});
//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;    return scrollTop;
}
//可视窗口高度
function getWindowHeight() {
    var windowHeight = 0;
    if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
    return scrollHeight;

}
window.onscroll=function(){
    var loadFlag;
    if(vm.isScreen==2){
        loadFlag = vm.commentList.lastPage;
    }else{
        if(vm.value==1){
            loadFlag = vm.myPostsList.lastPage;
        }else if(vm.value==2){
            loadFlag = vm.friendDynamic.lastPage;
        }
    }
    //监听事件内容
    if(getScrollHeight()==getWindowHeight() + getDocumentTop()){
        //当滚动条到底时,这里是触发内容
        if(!loadFlag){
            vm.loadFlag=true;
            vm.pageNumber++;
            if(vm.isScreen==2){
                vm.getInfoMediaAdvCommentList();
            }else{
                if(vm.value==1){
                    vm.myPosts();
                }else if(vm.value==2){
                    vm.myRepliesPosts();
                }
            }
        }else{
            vm.$refs.prompt.toast("没有更多了！")
        }
    }
};